package cn.edu.ctbu.dp01.api;

import cn.edu.ctbu.dp01.entity.teacher;
import cn.edu.ctbu.dp01.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/teacher")
public class TeacherApiController {

    @Autowired
    private final TeacherService teacherService;

    public TeacherApiController(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    @GetMapping("/list")
    public List<teacher> findAll() {
        return teacherService.getAll();
    }

    @GetMapping("/{id}")
    public teacher findById(@PathVariable int id) {
        return teacherService.getById(id);
    }

    @PostMapping("/add")
    public teacher add(@RequestBody teacher teacher) {
        return teacherService.add(teacher);
    }

    @PutMapping("/update")
    public teacher update(@RequestBody teacher teacher) {
        return teacherService.update(teacher);
    }

    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable Integer id) {
        teacherService.delete(id);
    }
}